package me.zhengjie.modules.serviceprovider.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.serviceprovider.domain.TServiceproviderOrderAppraise;
import me.zhengjie.modules.serviceprovider.service.TServiceproviderOrderAppraiseService;
import me.zhengjie.modules.serviceprovider.service.dto.TServiceproviderOrderAppraiseQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @author xuyukun
* @date 2019-08-25
*/
@RestController
@RequestMapping("api")
public class TServiceproviderOrderAppraiseController {

    @Autowired
    private TServiceproviderOrderAppraiseService tServiceproviderOrderAppraiseService;

    @Log("查询TServiceproviderOrderAppraise")
    @GetMapping(value = "/tServiceproviderOrderAppraise")
    @PreAuthorize("hasAnyRole('ADMIN','TSERVICEPROVIDERORDERAPPRAISE_ALL','TSERVICEPROVIDERORDERAPPRAISE_SELECT')")
    public ResponseEntity getTServiceproviderOrderAppraises(TServiceproviderOrderAppraiseQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity(tServiceproviderOrderAppraiseService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @Log("新增TServiceproviderOrderAppraise")
    @PostMapping(value = "/tServiceproviderOrderAppraise")
    @PreAuthorize("hasAnyRole('ADMIN','TSERVICEPROVIDERORDERAPPRAISE_ALL','TSERVICEPROVIDERORDERAPPRAISE_CREATE')")
    public ResponseEntity create(@Validated @RequestBody TServiceproviderOrderAppraise resources){
        return new ResponseEntity(tServiceproviderOrderAppraiseService.create(resources),HttpStatus.CREATED);
    }

    @Log("修改TServiceproviderOrderAppraise")
    @PutMapping(value = "/tServiceproviderOrderAppraise")
    @PreAuthorize("hasAnyRole('ADMIN','TSERVICEPROVIDERORDERAPPRAISE_ALL','TSERVICEPROVIDERORDERAPPRAISE_EDIT')")
    public ResponseEntity update(@Validated @RequestBody TServiceproviderOrderAppraise resources){
        tServiceproviderOrderAppraiseService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @Log("删除TServiceproviderOrderAppraise")
    @DeleteMapping(value = "/tServiceproviderOrderAppraise/{id}")
    @PreAuthorize("hasAnyRole('ADMIN','TSERVICEPROVIDERORDERAPPRAISE_ALL','TSERVICEPROVIDERORDERAPPRAISE_DELETE')")
    public ResponseEntity delete(@PathVariable Integer id){
        tServiceproviderOrderAppraiseService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}